From 4eeb6a1204b799d8347a1561b047563821371801 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 30 Aug 2005 12:40:35 +0000 Subject: [PATCH] added models test, removed redundant tests --- ChangeLog | 12 +++ tests/Makefile.am | 10 +- tests/float_to_u8.c | 94 ------------------- tests/models.c | 178 ++++++++++++++++++++++++++++++++++++ tests/rgb_to_lab_to_rgb.c | 131 -------------------------- tests/rgb_to_ycbcr_to_rgb.c | 97 -------------------- tests/srgb_to_lab_u8.c | 10 +- tests/types.c | 73 ++++++++++----- tests/u8_to_float.c | 85 ----------------- 9 files changed, 247 insertions(+), 443 deletions(-) delete mode 100644 tests/float_to_u8.c create mode 100644 tests/models.c delete mode 100644 tests/rgb_to_lab_to_rgb.c delete mode 100644 tests/rgb_to_ycbcr_to_rgb.c delete mode 100644 tests/u8_to_float.c diff --git a/ChangeLog b/ChangeLog index 4bbacbe..9c5df22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-08-30 Øyvind Kolås + + * tests/srgb_to_lab_u8.c: updated values. + * tests/types.c: rewritten. + * tests/models.c: added, a test to test that reference conversions + registered for a BablModel are symmetrical. + * tests/float_to_u8.c, + * tests/u8_to_float.c, + * tests/rgb_to_lab_to_rgb.c, + * tests/rgb_to_ycbcr_to_rgb.c: removed. + * tests/Makefile.am: updated. + 2005-08-30 Øyvind Kolås * babl/babl-introspect.c: diff --git a/tests/Makefile.am b/tests/Makefile.am index d9c82bb..429c716 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,27 +1,21 @@ TESTS = \ - float_to_u8 \ grayscale_to_rgb \ - u8_to_float \ rgb_to_bgr \ - rgb_to_lab_to_rgb \ rgb_to_ycbcr \ - rgb_to_ycbcr_to_rgb \ srgb_to_lab_u8 \ sanity \ types \ + models \ babl_class_name -float_to_u8_SOURCES = float_to_u8.c -u8_to_float_SOURCES = u8_to_float.c grayscale_to_rgb_SOURCES = grayscale_to_rgb.c rgb_to_bgr_SOURCES = rgb_to_bgr.c -rgb_to_lab_to_rgb_SOURCES = rgb_to_lab_to_rgb.c srgb_to_lab_u8_SOURCES = srgb_to_lab_u8.c rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c -rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c babl_class_name_SOURCES = babl_class_name.c sanity_SOURCES = sanity.c types_SOURCES = types.c +models_SOURCES = models.c AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c deleted file mode 100644 index 3d10222..0000000 --- a/tests/float_to_u8.c +++ /dev/null @@ -1,94 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "babl.h" -#include "babl-internal.h" - -#define BUFFER_LENGTH 6 - -float float_buf[BUFFER_LENGTH]= -{ - 0.0, - 1.0, - -1.0, - 2.0, - 0.5, - 0.25, -}; - -unsigned char u8_buf [BUFFER_LENGTH]; -unsigned char u8_ref_buf [BUFFER_LENGTH]= -{ - 0, - 255, - 0, - 255, - 127, - 63, -}; - -int -test_float_to_rgb_u8 (void) -{ - Babl *fish; - int i; - int OK=1; - - - fish = babl_fish ( - babl_format_new ( - babl_model ("Y"), - babl_type ("float"), - babl_component ("Y"), - NULL - ), - babl_format_new ( - babl_model ("Y"), - babl_type ("u8"), - babl_component ("Y"), - NULL - )); - - babl_process (fish, - float_buf, u8_buf, - BUFFER_LENGTH); - - for (i=0; i +#include "babl.h" +#include "math.h" +#include "babl-internal.h" + +int OK=1; + +#define pixels 1024 +#define TOLERANCE 0.001 + +double test[pixels * 4]; + +double r_interval (double min, double max) +{ + long int rand_i = random (); + double ret; + ret = (double) rand_i / RAND_MAX; + ret*=(max-min); + ret+=min; + return ret; +} + +void test_init (void) +{ + double r_min = -0.2, + r_max = 1.5, + g_min = -0.2, + g_max = 1.5, + b_min = -0.2, + b_max = 1.5, + a_min = -0.5, + a_max = 1.5; + int i; + double r,g,b,a; + for (i=0;imodel.components; i++) + { + argument[args++] = model->model.component[i]; + } + argument[args++] = NULL; + +#define o(argno) argument[argno], + return babl_format_new (o(0) o(1) o(2) o(3) + o(4) o(5) o(6) o(7) + o(8) o(9) o(10) o(11) + o(12) o(13) o(14) o(15) + o(16) o(17) o(18) o(19) + o(20) o(21) o(22) o(23) + o(24) o(25) o(26) o(27) + o(28) o(29) o(30) o(31) + o(32) o(33) o(34) o(35) + o(36) o(37) o(38) o(39) + o(40) o(41) o(42) NULL); +#undef o +} + +int model_check (Babl *babl, + void *userdata) +{ + void *original; + double *clipped; + void *destination; + double *transformed; + + Babl *ref_fmt; + Babl *fmt; + Babl *fish_to; + Babl *fish_from; + + ref_fmt = reference_format (); + fmt = construct_double_format (babl); + fish_to = babl_fish (ref_fmt, fmt); + fish_from = babl_fish (fmt, ref_fmt); + + original = babl_calloc (1,64/8 * babl->model.components * pixels); + clipped = babl_calloc (1,64/8 * 4 * pixels); + destination = babl_calloc (1,64/8 * babl->model.components * pixels); + transformed = babl_calloc (1,64/8 * 4 * pixels); + + babl_process (fish_to, test, original, pixels); + babl_process (fish_from, original, clipped, pixels); + babl_process (fish_to, clipped, destination, pixels); + babl_process (fish_from, destination, transformed, pixels); + + { + int i; + int log=0; + + for (i=0;iTOLERANCE) + { + log=1; + OK=0; + } + if (log && log < 5) + { + babl_log ("%s", babl->instance.name); + babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0], + test [i*4+1], + test [i*4+2], + test [i*4+3]); + babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i*4+0], + clipped [i*4+1], + clipped [i*4+2], + clipped [i*4+3]); + babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i*4+0], + transformed [i*4+1], + transformed [i*4+2], + transformed [i*4+3]); + log++; + OK=0; + } + } + } + + babl_free (original); + babl_free (clipped); + babl_free (destination); + babl_free (transformed); + return 0; +} + +int main (void) +{ + babl_init (); + test_init (); + + babl_set_extender (babl_extension_quiet_log ()); + babl_model_each (model_check, NULL); + + babl_destroy (); + + return !OK; +} diff --git a/tests/rgb_to_lab_to_rgb.c b/tests/rgb_to_lab_to_rgb.c deleted file mode 100644 index 19a6ca6..0000000 --- a/tests/rgb_to_lab_to_rgb.c +++ /dev/null @@ -1,131 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#include -#include "babl.h" -#include "babl-internal.h" - -#define PIXELS 32 -#define TOLERANCE 0.001 - -float source_buf [PIXELS*3]= - {1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, - 0.0, 1.0, 1.0, - 0.0, 1.0, 0.0, - 1.0, 0.0, 1.0, - 1.0, 0.0, 0.0, - 1.0, 0.0, 1.0, - 0.0, 0.0, 0.0, - - 0.75, 0.75, 0.75, - 0.75, 0.75, 0.75, - 0.0, 0.75, 0.75, - 0.0, 0.75, 0.0, - 0.75, 0.0, 0.75, - 0.75, 0.0, 0.0, - 0.75, 0.0, 0.75, - 0.0, 0.0, 0.0, - - 0.5, 0.5, 0.5, - 0.5, 0.5, 0.5, - 0.0, 0.5, 0.5, - 0.0, 0.5, 0.0, - 0.5, 0.0, 0.5, - 0.5, 0.0, 0.0, - 0.5, 0.0, 0.5, - 0.0, 0.0, 0.0, - - 0.25, 0.25, 0.25, - 0.25, 0.25, 0.25, - 0.0, 0.25, 0.25, - 0.0, 0.25, 0.0, - 0.25, 0.0, 0.25, - 0.25, 0.0, 0.0, - 0.25, 0.0, 0.25, - 0.0, 0.0, 0.0 - }; - -float temp_buf [PIXELS*3]; -float destination_buf [PIXELS*3]; - -int -test (void) -{ - Babl *fish; - int i; - int OK=1; - - - fish = babl_fish ( - babl_format_new ( - "name", "foo", - babl_model ("RGB"), - babl_type ("float"), - babl_component ("R"), - babl_component ("G"), - babl_component ("B"), - NULL - ), - babl_format_new ( - "name", "bar", - babl_model ("CIE Lab"), - babl_type ("float"), - babl_component ("CIE L"), - babl_component ("CIE a"), - babl_component ("CIE b"), - NULL - ) - ); - - babl_process (fish, source_buf, temp_buf, PIXELS); - - /* this test tests both pixel format creation, and the scope of - * babl_fish()'s polymorphism - */ - fish = babl_fish ("bar","foo"); - - babl_process (fish, temp_buf, destination_buf, PIXELS); - - for (i=0; i TOLERANCE) - { - babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f", - i, i,i%3, i,i/3, destination_buf[i], source_buf[i]); - OK=0; - } - } - - if (!OK) - return -1; - return 0; -} - -int -main (int argc, - char **argv) -{ - babl_init (); - if (test()) - return -1; - babl_destroy (); - return 0; -} diff --git a/tests/rgb_to_ycbcr_to_rgb.c b/tests/rgb_to_ycbcr_to_rgb.c deleted file mode 100644 index 117aba0..0000000 --- a/tests/rgb_to_ycbcr_to_rgb.c +++ /dev/null @@ -1,97 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#include -#include "babl.h" -#include "babl-internal.h" - -#define PIXELS 6 -#define TOLERANCE 0.00002 - -float source_buf [PIXELS*3]= - {0.0, 0.0, 0.0, - 0.5, 0.5, 0.5, - 1.0, 1.0, 1.0, - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0}; - -float temp_buf [PIXELS*3]; -float destination_buf [PIXELS*3]; - -int -test (void) -{ - Babl *fish; - int i; - int OK=1; - - fish = babl_fish ( - babl_format_new ( - "name", "foo", - babl_model ("RGB"), - babl_type ("float"), - babl_component ("R"), - babl_component ("G"), - babl_component ("B"), - NULL - ), - babl_format_new ( - "name", "bar", - babl_model ("Y'CbCr"), - babl_type ("float"), - babl_component ("Y'"), - babl_component ("Cb"), - babl_component ("Cr"), - NULL - ) - ); - - babl_process (fish, source_buf, temp_buf, PIXELS); - - fish = babl_fish (babl_format ("bar"), - babl_format ("foo")); - - babl_process (fish, temp_buf, destination_buf, PIXELS); - - for (i=0; i TOLERANCE) - { - babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f", - i, i,i%3, i,i/3, destination_buf[i], source_buf[i]); - OK=0; - } - } - if (!OK) - return -1; - return 0; -} - -int -main (int argc, - char **argv) -{ - babl_init (); - if (test()) - return -1; - babl_destroy (); - return 0; -} diff --git a/tests/srgb_to_lab_u8.c b/tests/srgb_to_lab_u8.c index fc7b024..1b24b24 100644 --- a/tests/srgb_to_lab_u8.c +++ b/tests/srgb_to_lab_u8.c @@ -34,11 +34,11 @@ unsigned char source_buf [PIXELS*3]= unsigned char reference_buf [PIXELS*3]= { 0, 128, 128, - 135, 128, 128, - 255, 128, 128, - 135, 208, 195, - 223, 41, 211, - 82, 207, 20}; + 135, 128, 127, + 254, 127, 128, + 135, 207, 195, + 222, 42, 210, + 81, 206, 20}; unsigned char destination_buf [PIXELS*3]; diff --git a/tests/types.c b/tests/types.c index acda129..0cb951b 100644 --- a/tests/types.c +++ b/tests/types.c @@ -4,12 +4,28 @@ int OK=1; -double test[] = { - 0.0, 0.5, 1.0, 0.1, 0.9, 1.1, -0.1, -2, 2.0, 100, -100, 200, 200 -}; +#define TOLERANCE 0.0046 +#define samples 2048 +double test[samples]; -int samples = sizeof(test) / sizeof(test[0]); +double r_interval (double min, double max) +{ + long int rand_i = random (); + double ret; + ret = (double) rand_i / RAND_MAX; + ret*=(max-min); + ret+=min; + return ret; +} +void test_init (double min, double max) +{ + int i; + for (i=0;itype.bits/8 * samples); - clipped = babl_calloc (1,64/8 * samples); - destination = babl_calloc (1,babl->type.bits/8 * samples); - transformed = babl_calloc (1,64/8 * samples); - + ref_fmt = double_vector_format (); fmt = babl_format_new (babl_model ("Y"), babl, babl_component ("Y"), NULL); + fish_to = babl_fish (ref_fmt, fmt); + fish_from = babl_fish (fmt, ref_fmt); - babl_process (babl_fish (double_vector_format (), fmt), - test, original, samples); - babl_process (babl_fish (fmt, double_vector_format ()), - original, clipped, samples); - babl_process (babl_fish (double_vector_format (), fmt), - clipped, destination, samples); - babl_process (babl_fish (fmt, double_vector_format ()), - destination, transformed, samples); + original = babl_calloc (1,babl->type.bits/8 * samples); + clipped = babl_calloc (1,64/8 * samples); + destination = babl_calloc (1,babl->type.bits/8 * samples); + transformed = babl_calloc (1,64/8 * samples); + + babl_process (fish_to, test, original, samples); + babl_process (fish_from, original, clipped, samples); + babl_process (fish_to, clipped, destination, samples); + babl_process (fish_from, destination, transformed, samples); + { + int cnt=0; int i; for (i=0;i0.00001) - babl_log ("%s: %f %f %f)", - babl->instance.name, test[i], clipped[i], transformed[i] - ); - OK=0; + if (fabs (clipped[i] - transformed[i])> TOLERANCE) + { + if (cnt++<4) + babl_log ("%s: %f %f %f)", + babl->instance.name, test[i], clipped[i], transformed[i] + ); + OK=0; + } } } @@ -75,9 +99,12 @@ int main (void) { babl_init (); + test_init (0.0, 182.0); + babl_set_extender (babl_extension_quiet_log ()); babl_type_each (type_check, NULL); + babl_introspect (NULL); babl_destroy (); return !OK; diff --git a/tests/u8_to_float.c b/tests/u8_to_float.c deleted file mode 100644 index d49c812..0000000 --- a/tests/u8_to_float.c +++ /dev/null @@ -1,85 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "babl.h" -#include -#include "babl-internal.h" - -#define BUFFER_LENGTH 4 -#define TOLERANCE 0.003 - -unsigned char u8_buf [BUFFER_LENGTH]= { 0, 255, 127, 63, }; -float float_ref_buf[BUFFER_LENGTH] = { 0.0, 1.0, 0.5, 0.25, }; -float float_buf [BUFFER_LENGTH]; - -int -test (void) -{ - Babl *fish; - int i; - int OK=1; - - - fish = babl_fish ( - babl_format_new ( - babl_model ("Y"), - babl_type ("u8"), - babl_component ("Y"), - NULL - ), - babl_format_new ( - babl_model ("Y"), - babl_type ("float"), - babl_component ("Y"), - NULL - )); - - babl_process (fish, - u8_buf, float_buf, - BUFFER_LENGTH); - - for (i=0; i TOLERANCE) - { - babl_log ("%i .. %f-%f=%f", - u8_buf[i], float_buf[i], float_ref_buf[i], - fabs (float_buf[i] - float_ref_buf[i]) - ); - OK=0; - } - } - if (!OK) - return -1; - return 0; -} - -int -main (int argc, - char **argv) -{ - babl_init (); - if (test()) - return -1; - babl_destroy (); - return 0; -} - - - -- 2.30.2